﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using DAO;
using DTO;

namespace Presentation
{
    public partial class UserControlLieu : UserControl
    {
        public UserControlLieu()
        {
            InitializeComponent();
        }


        private void btnThoat_Click(object sender, EventArgs e)
        {
            this.Visible = false;
        }

        private void btnTracuu_Click(object sender, EventArgs e)
        {
            try
            {
                DateTime tngay = DateTime.Parse(dtpTungay.Text);
                DateTime dngay = DateTime.Parse(dtpDenngay.Text);
                HinhThucBanDao htbDao = new HinhThucBanDao();
                HinhThucBanDto[] htbDto = htbDao.SelectHinhThucBan(tngay, dngay, (int)MyConnection.Hinhthucban.Lieu);
                
                dgvLieu.AutoGenerateColumns = false;
                dgvLieu.DataSource = htbDto;
                float sum = 0;
                for (int i = 0; i < dgvLieu.Rows.Count; i++)
                {
                    sum = sum + float.Parse(dgvLieu.Rows[i].Cells[5].Value.ToString());
                }
                txtTongtien.Text = Convert.ToDecimal(sum).ToString();
            }
            catch (Exception)
            {

                MessageBox.Show("Không có dữ liệu");
            }
           
            
        }

        private void UserControlLieu_Load(object sender, EventArgs e)
        {

        }

        private void dgvLieu_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
        {
            DataGridView grv = (DataGridView)sender;
            Utils.MakeSothutuColumn(grv, "itemStt");
        }

        private void btnLuuBaoCao_Click(object sender, EventArgs e)
        {
            Utils.ExportToExcel(dgvLieu);
        }
    }
}
